<?php namespace Summer\Userhub\Updates;

use Schema;
use Winter\Storm\Database\Updates\Migration;

class UserAddBaseFields extends Migration
{
    public function up()
    {
        if (Schema::hasColumns('users', [
            'userphone',
            'realname',
            'nickname',
            'referrer_code',
            'password_safe',
            'birthday',
            'idcard',
        ])) {
            return;
        }

        Schema::table('users', function($table)
        {
            $table->string('userphone')->nullable();//手机号
            $table->string('realname')->nullable();//真实姓名
            $table->string('nickname')->nullable();//昵称
            $table->string('referrer_code')->nullable();//推荐邀请码
            $table->string('password_safe')->nullable();//安全密码
            $table->string('birthday')->nullable();//生日
            $table->string('idcard')->nullable();//身份证号

        });
    }

    public function down()
    {
        if (Schema::hasTable('users')) {
            Schema::table('users', function ($table) {
                $table->dropColumn([
                    'userphone',
                    'realname',
                    'nickname',
                    'referrer_code',
                    'password_safe',
                    'birthday',
                    'idcard',
                ]);
            });
        }
    }
}
